<template>
  <div>
    列表动画的使用
    <button @click="add">添加</button>
    <button @click="del">删除</button>
    <transition-group appear name="why" tag="p">
      <span class="item" v-for="item in numbers" :key="item">{{ item }}</span>
    </transition-group>
  </div>
</template>

<script>
export default {
  name: "App",
  components: {},
  data() {
    return {
      numbers: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
      numCounter: 10,
    };
  },
  methods: {
    add() {
      // this.numbers.push(this.numCounter++);
      this.numbers.splice(this.radomIndex(), 0, this.numCounter++);
    },
    del() {
      this.numbers.splice(this.radomIndex(), 1);
    },
    radomIndex() {
      return Math.floor(Math.random() * this.numbers.length);
    },
  },
};
</script>

<style>
.item {
  margin: 3px;
  display: inline-block;
}
/* inline->inline-block */
.why-enter-from,
.why-leave-to {
  opacity: 0;
  transform: translateY(30px);
}

.why-enter-active,
.why-leave-active {
  transition: all 1s ease;
}
</style>
